home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-20 / nos_kit3.zip / TNC_TNC2.ZIP / TNC2BOTH.MAC < prev    next >
Text File  |  1987-05-26  |  7KB  |  243 lines

  1. From bellcore!@wiscvm.wisc.edu:BOBW@USU.BITNET Fri Feb  6 03:24:15 1987
  2. Received: from sdcsvax.UCSD.EDU by flash.bellcore.com (4.12/4.7)
  3.     id AA05584; Fri, 6 Feb 87 05:18:57 est
  4. Received: by sdcsvax.UCSD.EDU (5.57/4.42)
  5.     id AA17792 for boesch@umunhum.stanford.edu; Thu, 5 Feb 87 20:28:08 PST hops=0
  6. Message-Id: <8702060428.AA17792@sdcsvax.UCSD.EDU>
  7. Received: from USU.BITNET by wiscvm.wisc.edu on 02/05/87 at 17:50:17 CST
  8. Date: 5 FEB 87 16:38-MDT
  9. From: BOBW@usu.bitnet
  10. To: TCP-GROUP@sdcsvax.ucsd.edu
  11. Subject: This is the KISSTNC/HOWIE source code....
  12.  
  13. Status: R
  14.  
  15. ; KISS-TNC-HEX-LOADER.MAC -  KISS TNC Intel Hex Loader v0.2
  16. ; k3mc 8 Aug 86 v0.1
  17. ;      4 Oct 86 v0.2
  18. ; v0.2 correctly sets the SP for either 16k or 32k of RAM, and strips
  19. ; the parity bit from incoming chars.
  20.  
  21.     .z80
  22.     aseg
  23.     org    100h
  24.     .phase    4800h        ;CHANGED TO 4800H   WA7MXZ DEC. 10, 1986
  25.                            ;keep the loader happy...
  26.  
  27. RAM    equ    8000h        ;Where the 16k x 8 (or 32k x 8) of RAM begins
  28.  
  29. ENQ    equ    5h
  30. ACK    equ    6h
  31. NAK    equ    15h
  32. colon    equ    ':'
  33.  
  34. rr_eof    equ    1        ;Record Type for End of File / begin execution
  35.  
  36.  
  37. ; SIO equates
  38.  
  39. SIO    equ    0dch        ;actually, only A5 is used for SIO -cs
  40.  
  41. A_dat    equ    SIO+0        ;Modem port
  42. A_ctl    equ    SIO+1        ;Modem port
  43.  
  44. B_dat    equ    SIO+2        ;user serial port
  45. B_ctl    equ    SIO+3        ;user serial port
  46.  
  47. RR0_RXR    equ    1        ;Receiver Char Avail bit
  48. RR0_TBE    equ    4        ;TX Buffer Empty bit
  49.  
  50.  
  51.  
  52. ;
  53. ; The general form of an Intel HEX record is as follows:
  54. ;
  55. ; :LLaaaaRRdddd..ddCC
  56. ;
  57. ; where LL is the number of bytes of data between RR and CC,
  58. ; not including RR or CC.
  59. ; aaaa is an address (see below),
  60. ; RR is a record type,
  61. ; dd are data bytes,
  62. ; and CC is a checksum, calculated as follows:
  63. ;   CC = - ( LL + aaaa + RR + dd + dd + ... ( modulo 256 ) )
  64. ; That is, adding all the bytes LL to CC (inclusive), you should get zero.
  65. ;
  66. ; These are the record types needed:
  67. ; RR = 00 record type = data. aaaa is the load address for the data.
  68. ; RR = 01 record type = end of file.
  69. ;  aaaa is the beginning execution address. LL is 00.
  70. ;  :00aaaa01CC
  71. ;  So, for example, if the start address is 8000, the last line of the file is
  72. ;  :008000017F
  73. ;
  74. ; In this implementation, trailing checksums are ignored; you don't even have
  75. ; to include them.
  76. ;-----------------------------------------------------------------------------
  77. start:
  78.     di            ;for this test, NO INTERRUPTS!
  79.  
  80. ; Figure out where top of stack is, set stack pointer.
  81. ; silly TNC-2 does not do complete address decoding for the RAMs if you are
  82. ; using only the two 8k x 8 chips.  Hack to figure out top of memory so we can
  83. ; set stack pointer.  This is REQUIRED by the KISS TNC.
  84.  
  85.     ld    a,55h        ;one value
  86.     ld    (0bfffh),a
  87.  
  88.     ld    a,0aah
  89.     ld    (0ffffh),a    ;other value
  90.  
  91.     ld    a,(0bfffh)    ;get what should be 55h if 32k
  92.  
  93.     cp    55h
  94.     ld    sp,0        ;assume for the moment it is
  95.     jr    z,stack_loaded    ;if so, then we've found TOS
  96.     ld    sp,0c000h    ;else all we've got is two 8k x 8 RAMs
  97. stack_loaded:
  98.  
  99. ;init SIO for async
  100.  
  101.     ld    b,nb        ;n bytes for init
  102.     ld    c,B_ctl        ;to B port
  103.     ld    hl,binit    ;with these bytes
  104.     otir            ;NOW!
  105.  
  106.     ld    a,5
  107.     out    (A_ctl),a    ;Ready WR5
  108.     ld    a,80h
  109.     out    (A_ctl),a    ;turn off STATUS LED
  110.  
  111. loop:
  112.     call    getchar        ;returns char into A reg
  113.     cp    ENQ        ;is it Control-E character?
  114.     jr    z,ENQCHR    ;yes, deal with it
  115.     cp    colon
  116.     jr    z,saw_colon    ;Go into Intel Hex download mode
  117.     and   5fh            ;UPPER CASE ONLY     ADDED BY WA7MXZ
  118.     cp    'H'            ; H for HOWIE of course
  119.     jp    z,00EDH        ;go get em' HOWIE
  120.     call    putchar        ;if neither, just echo it
  121.     jr    loop
  122.  
  123. ENQCHR:
  124.     ld    hl,ENQ_string
  125. ENQ_loop:
  126.     ld    a,(hl)
  127.     or    a
  128.     jr    z,loop
  129.     call    putchar
  130.     inc    hl
  131.     jr    ENQ_loop
  132.  
  133. saw_colon:
  134.     call    rdbyte
  135.     EX    AF,AF'        ;save in other register set for a sec
  136.     call    rdbyte
  137.     ld    h,a
  138.     call    rdbyte
  139.     ld    l,a
  140.     call    rdbyte
  141.     cp    rr_eof        ;is it record type 1 (begin execution)?
  142.     jr    nz,data_record    ;no, it's just another data record
  143. ;else we give machine to downloaded program
  144.     jp    (hl)        ;and go do it!
  145.  
  146. data_record:
  147.     EX    AF,AF'        ;get length value back
  148.     ld    b,a        ;and ready loop index
  149. load_loop:
  150.     call    rdbyte
  151.     ld    (hl),a
  152.     inc    hl
  153.     djnz    load_loop    ;load 'em up!
  154.  
  155. ; Note, we ignore checksums completely
  156.  
  157. find_colon:
  158.     call    getchar
  159.     cp    colon
  160.     jr    nz,find_colon    ;spin for a colon
  161.     jr    saw_colon    ;when we find colon, deal with next record
  162.  
  163. ;*** Reads 2 characters from SIO, converts them to binary, and returns value
  164. ;*** into A reg.  Disturbs no registers except AF.
  165. rdbyte:
  166.     push    bc
  167.     call    getchar
  168.     call    mk_binary
  169.     rlca
  170.     rlca
  171.     rlca
  172.     rlca
  173.     ld    b,a        ;save hi part
  174.     call    getchar
  175.     call    mk_binary
  176.     or    b        ;get hi + lo parts
  177.     pop    bc        ;be tidy
  178.     ret
  179.  
  180. ;*** Convert the ASCII character into Binary character (src & dest is A reg)
  181. mk_binary:
  182.     push    hl
  183.     push    de
  184.     call    makeUC        ;if anybody uses lower case, it's OK
  185.     sub    '0'        ;convert ASCII -> binary (sorta)
  186.     ld    d,0
  187.     ld    e,a
  188.     ld    hl,btable    ;base of translation table
  189.     add    hl,de        ;produce pointer into table
  190.     ld    a,(hl)        ;get corresponding binary
  191.     pop    de
  192.     pop    hl        ;cleanliness is next to Godliness
  193.     ret
  194.  
  195. btable:    defb    0,1,2,3,4,5,6,7,8,9,0,0,0,0,0,0,0,0ah,0bh,0ch,0dh,0eh,0fh
  196.  
  197. ;*** If the character in A reg is lower case, this makes it upper case.
  198. makeUC:
  199.     cp    'a'
  200.     ret    c        ;if less than an 'a' we're done
  201.     cp    'z'+1
  202.     ret    nc        ;if > than 'z', not a letter, so we're done
  203.     and    5fh        ;else force to UPPER CASE
  204.     ret
  205.  
  206. ;*** Get a char from user TTY (Port B), no interrupt mode. Return it in A reg.
  207. getchar:
  208.     in    a,(B_ctl)
  209.     and    RR0_RXR
  210.     jr    z,getchar    ;wait for a character to be typed
  211.     in    a,(B_dat)
  212.     and    7fh        ;strip parity bit (Phil's suggestion)
  213.     ret
  214.  
  215.  
  216. ;*** Put a character to user TTY (Port B), no interrupts.  Char is in A reg.
  217. putchar:
  218.     push    af        ;we will need A
  219. ploop:
  220.     in    a,(B_ctl)
  221.     and    RR0_TBE
  222.     jr    z,ploop        ;Wait for Transmitter buffer to become empty
  223.  
  224.     pop    af
  225.     out    (B_dat),a
  226.     ret
  227.  
  228.  
  229.  
  230. binit:    defb    1ah,0,14h,44h,3,0c3h,5,0eeh,11h,0    ;magic SIO inits
  231. bi_end    equ    $
  232. nb    equ    bi_end-binit    ;Number of bytes in previous string
  233.  
  234. ENQ_string:
  235.     defb    "KISS/Raw TNC Intel Hex Loader v0.2  4 Oct 86",13,10,0
  236. pad:    defb    0ffh,0ffh,0ffh,0ffh,0ffh,0ffh,0ffh,0ffh,0ffh,0ffh
  237.     defb    0ffh,0ffh,0ffh,0ffh,0ffh,0ffh,0ffh,0ffh,0ffh,0ffh
  238.     defb    0ffh,0ffh,0ffh,0ffh,0ffh,0ffh,0ffh,0ffh,0ffh,0ffh
  239.     defb    0ffh,0ffh,0ffh,0ffh,0ffh,0ffh,0ffh,0ffh,0ffh,0ffh
  240.     END    START
  241.  
  242.  
  243.